<?php


namespace app\model\school;


use app\model\config\RegionModel;
use app\model\config\RecycleModel;
use think\Model;
use think\model\concern\SoftDelete;

class SchoolModel extends Model
{
    protected $name = 'school';
    protected $autoWriteTimestamp = true;

    use SoftDelete;
    protected $defaultSoftDelete = 0;

    public function schoolBase()
    {
        return $this->hasOne(SchoolBaseModel::class, 'id', 'base_id')->bind(['base_name' => 'name']);
    }

    public function region()
    {
        return $this->hasOne(RegionModel::class, 'id', 'city_id')->bind(['city_name' => 'name']);
    }

    public static function onBeforeDelete(Model $model)
    {
        $recycleModel = new RecycleModel();
        $data = [
            'uid' => $model->id,
            'type' => 1,
            'title' => $model['name']
        ];
        $recycleModel->save($data);
    }
}